/**
 * Created by Administrator on 2017/4/11.
 * 用户登录状态处理
 *
 */
import Vue from 'vue'
import VueCookie from "vue-cookie"

export default {

    state : {
        userInfo: ''
    },

    mutations: {
        getUserInfo (state, data) {
            state.userInfo = data;
        }
    },
    getters: {
        getUser (state){
           return state
        }
    },
    actions: {
        getUserInfo ({commit}) {
            return new Promise((resolve,reject) => {
                Vue.http.get('/api/current_user').then(res => {
                    const msg = res.body;
                    if(msg.Success){
                        commit('getUserInfo',msg.Data);
                        resolve(msg.Data);
                    }else{
                        reject(msg);
                    }
                })
            });
        }
    }

}
